package com.chinaisafe.user.vo.request;

import com.chinaisafe.base.common.validated.UpdateGroup;
import com.chinaisafe.user.entity.SysTenantApp;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

/**
 * SysTenantAppReqVO
 * Description: 租户授权应用请求对象
 *
 * @author tby
 * @date  2024-07-12 10:04:27
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Schema(name = "TenantAppAuthReq", description = "租户授权应用请求对象")
public class TenantAppAuthReq implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;


    @NotBlank(groups = UpdateGroup.class, message = "租户编码不能为空" )
    private String tenancyCode;

    @Schema(description = "授权的应用")
    private List<AppAuth> apps;

    @Data
    public class AppAuth implements Serializable{
        @Serial
        private static final long serialVersionUID = 1L;

        @Schema(description = "应用_id")
        @NotNull(groups = UpdateGroup.class, message = "应用_id不能为空" )
        private Long sysAppId;



        @Schema(description = "租期")
        private LocalDate tenancyDate;


        public SysTenantApp toSysTenantApp(String tenancyCode, int i) {
            SysTenantApp sysTenantApp = new SysTenantApp();
            sysTenantApp.setSysAppId(this.getSysAppId());
            sysTenantApp.setTenancyDate(this.getTenancyDate());
            sysTenantApp.setSeq(i);
            sysTenantApp.setIntegration(false);
            sysTenantApp.setShelf(false);
            sysTenantApp.setTenancyCode(tenancyCode);
            return sysTenantApp;
        }

    }


}
